//
//  TicketDetailViewController.m
//  lv678
//
//  Created by apple on 15/7/5.
//  Copyright (c) 2015年 lampshade. All rights reserved.
//  旅游票详情

#import "TicketDetailViewController.h"
#import "GZTicketDeatil.h"
#import "UIImageView+WebCache.h"
#import "GZDetailCell.h"
#import "GZTicketModel.h"
#import "TicketOrderController.h"
#import "orderDetailController.h"
#import "MJRefresh.h"
@interface TicketDetailViewController ()
@property (nonatomic,strong)NSArray *group;
@end

@implementation TicketDetailViewController


-(NSArray *)group{
    if (_group == nil) {
        NSMutableArray *arry = [NSMutableArray array];
        for (NSDictionary *dict in self.dataArry) {
            GZTicketDeatil *detail = [GZTicketDeatil ticketWithDict:dict];
            [arry addObject:detail];
        }
        _group = [arry copy];
    }
    return _group;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[GZDetailCell class] forCellReuseIdentifier:@"ticketDetail"];
    [self.tableView reloadData];
    self.navigationItem.title = @"景点分类";

}
- (void)loadNewData{
//    [self.tableView.header beginRefreshing];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.group.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identity = @"ticketDetail";
    GZTicketDeatil *model     = self.group[indexPath.row];
    GZDetailCell *cell        = [tableView dequeueReusableCellWithIdentifier:identity];
    if (cell == nil) {
         cell = [[GZDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity];//使用自定义单元格

    }

    //通过SDWebImage-master获取接口图片地址，然后获取网络图片
    [cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil];
    NSString *price  = [[[NSNumberFormatter alloc]init]stringFromNumber:model.price];
    cell.title.text  = model.productName;
    cell.detail.text = model.describe;
    cell.price.text  = price;
    cell.mark.text   = @"￥";
    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 1.0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    GZTicketDeatil *detail = self.group[indexPath.row];
//    TicketOrderController *order = [[TicketOrderController alloc]init];
    orderDetailController *order = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"orderd"];
    order.tid = detail.tid;
    order.image = detail.image;
    [self.navigationController pushViewController:order animated:YES];
    
}

@end
